package com.ruge.core.log;

import com.ruge.tool.str.StringTool;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * description: ReqRespLoggingProperties
 * create time at 2022/6/6 11:40
 *
 * @author alice.ruge
 * @since 0.0.3
 */

@ConfigurationProperties("ruge.logging.reqresp")
public class ReqRespLoggingProperties {
    private static final String DEFAULT_BLACK_URL_REGEX = "^https?://.*/health/?$|^https?://.*/info/?$";
    private String appendBlackUrlRegex;
    private String overrideBlackUrlRegex;
    private String sensitiveWords;
    private Boolean logHttpBody = true;

    public ReqRespLoggingProperties() {
    }

    public String getAppendBlackUrlRegex() {
        return this.appendBlackUrlRegex;
    }

    public void setAppendBlackUrlRegex(String appendBlackUrlRegex) {
        this.appendBlackUrlRegex = appendBlackUrlRegex;
    }

    public String getOverrideBlackUrlRegex() {
        return this.overrideBlackUrlRegex;
    }

    public void setOverrideBlackUrlRegex(String overrideBlackUrlRegex) {
        this.overrideBlackUrlRegex = overrideBlackUrlRegex;
    }

    public String getBlackUrlRegex() {
        if (!StringTool.isBlank(this.overrideBlackUrlRegex)) {
            return this.overrideBlackUrlRegex;
        } else {
            return StringTool.isBlank(this.appendBlackUrlRegex) ? "^https?://.*/health/?$|^https?://.*/info/?$" : "^https?://.*/health/?$|^https?://.*/info/?$|" + this.appendBlackUrlRegex;
        }
    }

    public String getSensitiveWords() {
        return this.sensitiveWords;
    }

    public void setSensitiveWords(String sensitiveWords) {
        this.sensitiveWords = sensitiveWords;
    }

    public Boolean getLogHttpBody() {
        return this.logHttpBody;
    }

    public void setLogHttpBody(Boolean logHttpBody) {
        this.logHttpBody = logHttpBody;
    }
}
